//
//  MHRedPacketViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/11/3.
//  Copyright © 2018年 acgera. All rights reserved.
//
#import "MHRedPacketHeaderView.h"
#import "MHRedPacketRecordViewController.h"
#import "MHRedPacketRecordViewModel.h"
#import "MHCommonCell.h"
@interface MHRedPacketRecordViewController ()
@property(nonatomic, strong) MHRedPacketRecordViewModel *viewModel;
@end

@implementation MHRedPacketRecordViewController
@dynamic viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *leftBarItem = [UIBarButtonItem mh_backItemWithTitle:nil imageName: @"icon_back" target:self action:@selector(_back)];
    // 4.这里可以设置导航栏的左右按钮 统一管理方法
    self.navigationItem.leftBarButtonItem = leftBarItem;
//    self.navigationController.na [self preferredStatusBarStyle];
     [self setNeedsStatusBarAppearanceUpdate];
}

- (void)_back{
    [self.viewModel.services popViewModelAnimated:YES]; //重新创建了
}

-(void)configureCell:(MHCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object
{
    [super configureCell:cell atIndexPath:indexPath withObject:object];
//    cell.textLabel.y =  10;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    MHRedPacketHeaderView *headerView = [MHRedPacketHeaderView mh_viewFromXib];
    [headerView.iconImage yy_setImageWithURL:[NSURL URLWithString:self.viewModel.list.userFace] placeholder:nil];
    headerView.messageLabel.text = self.viewModel.list.title;
    headerView.tipLabel.text = self.viewModel.list.redInfo;
    headerView.amountLabel.text = [NSString stringWithFormat:@"%.2f",self.viewModel.list.amount];
    if (self.viewModel.list.amount <= 0) {
        headerView.amountLabel.hidden = YES;
        headerView.saveAcountLabel.hidden = YES;
    }
    return headerView;
}


-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return (self.viewModel.list.amount <= 0) ? 250 : 298; //如果只查看记录要更新约束
}

-(UIEdgeInsets)contentInset
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}


@end
